package cn.itcast.web.controller.stat;

import cn.itcast.service.stat.StatService;
import cn.itcast.web.controller.BaseController;
import com.alibaba.dubbo.config.annotation.Reference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/stat")
public class StatController extends BaseController{

    @Reference
    private StatService statService;

    /**
     * 进入页面
     * http://localhost:8080/stat/toCharts.do?chartsType=factory
     * http://localhost:8080/stat/toCharts.do?chartsType=sell
     * http://localhost:8080/stat/toCharts.do?chartsType=online
     */
    @RequestMapping("/toCharts")
    public String toCharts(String chartsType){
        return "stat/stat-"+chartsType;
    }

    /**
     * 需求1：生产厂家销售统计
     */
    @RequestMapping("/factorySale")
    @ResponseBody
    public List<Map<String, Object>> factorySale(){
        List<Map<String, Object>> list = statService.getFactorySale();
        return list;
    }

    /**
     * 需求2：商品销售统计排行
     */
    @RequestMapping("/productSale")
    @ResponseBody
    public List<Map<String, Object>> getProductSale(){
        List<Map<String, Object>> list = statService.getProductSale(5);
        return list;
    }

    /**
     * 需求3：系统访问压力图，按小时统计访问人数
     */
    @RequestMapping("/online")
    @ResponseBody
    public List<Map<String, Object>> getOnline(){
        List<Map<String, Object>> list = statService.getOnline();
        return list;
    }



}